﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import mortal.game.view.common.*;

    public class WorshipConfig extends Object
    {
        public var infoVec:Vector.<TMainCityAdoreConfig>;
        private var _freeTimes:int = -1;
        private static var _instance:WorshipConfig;

        public function WorshipConfig()
        {
            if (_instance != null)
            {
                throw new Error(" WorshipConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_main_city_adore_config.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TMainCityAdoreConfig = null;
            var _loc_3:Object = null;
            if (!this.infoVec)
            {
                this.infoVec = new Vector.<TMainCityAdoreConfig>;
            }
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TMainCityAdoreConfig();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this.infoVec.push(_loc_2);
            }
            return;
        }// end function

        public function getInfoByTimes(param1:int) : TMainCityAdoreConfig
        {
            var _loc_2:int = 0;
            while (_loc_2 < this.infoVec.length)
            {
                
                if (param1 >= this.infoVec[_loc_2].minTimes && param1 <= this.infoVec[_loc_2].maxTimes)
                {
                    return this.infoVec[_loc_2];
                }
                _loc_2++;
            }
            return null;
        }// end function

        public function get freeTimes() : int
        {
            var _loc_1:int = 0;
            if (this._freeTimes < 0)
            {
                this._freeTimes = 0;
                _loc_1 = 0;
                while (_loc_1 < this.infoVec.length)
                {
                    
                    if (this.infoVec[_loc_1].cost == 0)
                    {
                        this._freeTimes = this.infoVec[_loc_1].maxTimes;
                    }
                    _loc_1++;
                }
            }
            return this._freeTimes;
        }// end function

        public static function get instance() : WorshipConfig
        {
            if (_instance == null)
            {
                _instance = new WorshipConfig;
            }
            return _instance;
        }// end function

    }
}
